package members_api
{
	import com.adobe.fiber.core.model_internal;
	import com.adobe.fiber.services.wrapper.HTTPServiceWrapper;
	
	import flash.events.EventDispatcher;
	import flash.system.Security;
	import flash.utils.Dictionary;
	
	import mx.controls.Alert;
	import mx.rpc.AbstractOperation;
	import mx.rpc.AsyncToken;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPMultiService;
	import mx.rpc.http.Operation;
	import mx.rpc.http.mxml.HTTPMultiService;
	import mx.rpc.http.mxml.HTTPService;
	
	import spark.core.IDisplayText;
	
	public class member_repository extends EventDispatcher 
	{
		private var operations:Dictionary = new Dictionary();
		private const appName:String = "Members";
		private const ipAddress:String = "localhost";		

		public function member_repository()
		{
			Security.loadPolicyFile("http://14.160.65.34/Members/crossdomain.xml");				

			var http_service:HTTPService = new HTTPService();
			http_service.url = "http://"+ipAddress+"/" + appName + "/GetHistory.ashx";
			http_service.method = "GET";
			http_service.showBusyCursor = true;
			http_service.resultType = Object;			
			operations["GetHistory"] = http_service;
			
			http_service = new HTTPService();
			http_service.url = "http://"+ipAddress+"/" + appName + "/Contact/GetRemoteContact";			
			http_service.resultType = Object;
			http_service.method = "GET";					
			http_service.showBusyCursor = true;
			operations["GetContact"] = http_service;

			http_service = new HTTPService();
			http_service.url = "http://"+ipAddress+"/" + appName + "/GetContacts.ashx";
			http_service.resultType = Object;
			http_service.method = "GET";
			http_service.showBusyCursor = true;
			operations["GetContacts"] = http_service;
			
			http_service = new HTTPService();
			http_service.url = "http://"+ipAddress+"/" + appName + "/SaveBookingInfo.ashx";
			http_service.resultType = Object;
			http_service.contentType = "application/x-www-form-urlencoded";
			http_service.showBusyCursor = true;
			http_service.method = "POST";
			operations["SaveBookingInfo"] = http_service;

			http_service = new HTTPService();
			http_service.url = "http://"+ipAddress+"/ga2004/ims/boxoffice/get_session.asp";
			http_service.method = "GET";
			http_service.resultType = Object;
			operations["GetUserLoginID"] = http_service;
		}
		
		protected function resultHandler(event:ResultEvent):void
		{
			// TODO Auto-generated method stub			
			var successEvent:ContactEvent = new ContactEvent(ContactEvent.RESULT, event.result);
			dispatchEvent(successEvent);
		}
		
		protected function faultHandler(event:FaultEvent):void
		{
			// TODO Auto-generated method stub
			var fault:ContactEvent = new ContactEvent(ContactEvent.FAULT, event.message);
			dispatchEvent(fault);
			//Alert.show(event.message.toString());
		}
		
		public function GetContact(memID:String, loginInfo:String):void{
			var operation:HTTPService = operations["GetContact"] as HTTPService;
			operation.addEventListener(ResultEvent.RESULT, resultHandler);
			operation.addEventListener(FaultEvent.FAULT, faultHandler);
			var url:String = operation.url + "?memberId="+ memID + "&loginInfo=" + loginInfo;
			operation.url = url;
			operation.send();
		}
	}
}